package com.zc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zc.dao.IPresDao;
import com.zc.domain.DoubleListData;
import com.zc.domain.FaultItem;
import com.zc.domain.FourPointsItem;
import com.zc.domain.Item;
import com.zc.domain.TwoPointsItem;
import com.zc.service.PresService;
import com.zc.service.RedisService;

@Controller
public class PresController {
	@Autowired
	private PresService presService;
	@Autowired
	private RedisService redisService;
	
	@RequestMapping(value = "/getSubPressure",method = RequestMethod.POST)
    public @ResponseBody List<Item> getSubPressure(){       	
		String key="subPressureData";
		List<Item> subPressureData=null;
		if(redisService.hasKey(key)){
			subPressureData=(List<Item>) redisService.get(key);
		}		
		else {
			subPressureData=presService.getSubPressure();
			redisService.set(key, subPressureData);
		}
		return subPressureData;
    }
	
	@RequestMapping(value = "/getMainPressure",method = RequestMethod.POST)
    public @ResponseBody List<Item> getMainPressure(){       	
		String key="mainPressureData";
		List<Item> mainPressureData=null;
		if(redisService.hasKey(key)){
			mainPressureData=(List<Item>) redisService.get(key);
		}		
		else {
			mainPressureData=presService.getMainPressure();
			redisService.set(key, mainPressureData);
		}
		return mainPressureData;
    }

	@RequestMapping(value = "/getPressure",method = RequestMethod.POST)
    public @ResponseBody List<TwoPointsItem> getPressure(){       	
		String key="pressureData";
		List<TwoPointsItem> pressureData=null;
		if(redisService.hasKey(key)){
			pressureData=(List<TwoPointsItem>) redisService.get(key);
		}		
		else {
			pressureData=presService.getPressure();
			redisService.set(key, pressureData);
		}
		return pressureData;
    }
}
